package oneDay;

public class middle3191 {

    public int minOperations(int[] nums) {
        return reversMinOperations(nums,3);
    }

    private int reversMinOperations(int[] nums, int i) {
        int count = 0;
        for (int j = 0; j < nums.length; j++) {
            if(j+i-1 >= nums.length){
                if(nums[j] == 1){
                    continue;
                }else{
                    return -1;
                }
            }
            if(nums[j] == 0){
                count++;
                // 反转
                int index = 0;
                while(index < i){
                    nums[j+index] = (nums[j+index] == 0 ? 1 : 0);
                    index++;
                }
            }
        }
        return count;
    }
}
